

//初始化单页view
var viewApi = mui('#app').view({
    defaultPage: '#setting'
});
//初始化单页的区域滚动
mui('#setting .mui-scroll-wrapper').scroll();

var view = viewApi.view;
(function($) {
    //处理view的后退与webview后退
    var oldBack = $.back;
    $.back = function() {
        if (viewApi.canBack()) { //如果view可以后退，则执行view的后退
            viewApi.back();
        } else { //执行webview后退
            oldBack();
        }
    };
    //监听页面切换事件方案1,通过view元素监听所有页面切换事件，目前提供pageBeforeShow|pageShow|pageBeforeBack|pageBack四种事件(before事件为动画开始前触发)
    //第一个参数为事件名称，第二个参数为事件回调，其中e.detail.page为当前页面的html对象
    view.addEventListener('pageBeforeShow', function(e) {
        var pageId = e.detail.page.id;
        console.log(pageId+ ' beforeShow');
        if(pageId="step2"){
        }
        if(pageId="step3"){
        }
        if (pageId = "step4") {
        }
    });
    view.addEventListener('pageShow', function(e) {
        // console.log(e.detail.page.id + ' show');
        //初始化单页的区域滚动
        mui('.mui-scroll-wrapper').scroll();
    });
    view.addEventListener('pageBeforeBack', function(e) {
        //console.log(e.detail.page.id + ' beforeBack');
    });
    view.addEventListener('pageBack', function(e) {
        //console.log(e.detail.page.id + ' back');
    });
})(mui);


//====================使用rem布局==============
(function(){
    function w() {
        var r = document.documentElement;
        var a = r.getBoundingClientRect().width;
        if (a > 750 ){
            a = 750;
        }
        var rem = a / 7.5;
        r.style.fontSize = rem + "px"
    }
    var t;
    w();
    window.addEventListener("resize", function() {
        clearTimeout(t);
        t = setTimeout(w, 300)
    }, false);
})();

// 60s倒计时
var wait=60;
var flag =true;
function time(o) {
    if (wait == 0) {
        o.removeAttribute("disabled");
        o.innerHTML="发送验证码";
        wait = 60;
        flag=true;
    } else {
        flag = false;
        o.setAttribute("disabled", true);
        o.innerHTML="重新发送(" + wait + ")";
        wait--;
        setTimeout(function () {
                time(o)
            },
            1000)
    }
}
mui.ready(function () {
    // 倒计时
    mui(".mui-input-row").on('tap', "#send", function () {
        if(flag){
            time(this);
            console.log("11")
        }else{

            console.log("22")
        }
    })

    // 提交数据
    mui(".mui-navbar-inner").on("tap","#submit",function () {
        // 判断input
        // 判断是否上传图片
        console.log("xxxxxxxxxx")
    })
})
